# encoding: utf-8

import datetime
from datetime import date, timedelta
import time

class TimeUtil:
    def __init__(self):
        pass

    @classmethod
    def getTodayStartAndEnd(cls,minite=0,formatstr="%Y-%m-%d %H:%M:%S"):
        start_time = datetime.datetime.now().strftime("%Y-%m-%d 00:00:00")
        end_time = datetime.datetime.now().strftime(formatstr)
        return (start_time,end_time)

    @classmethod
    def getStartAndEnd(cls,minite=0,formatstr="%Y-%m-%d %H:%M:%S"):
        start_time = ((datetime.datetime.now()) - datetime.timedelta(minutes=minite)).strftime(formatstr)
        end_time = datetime.datetime.now().strftime(formatstr)
        return (start_time,end_time)

    @classmethod
    def getDay(cls,days):
        return (date.today() + timedelta(days=days)).strftime("%Y-%m-%d")


    @classmethod
    def get_time_str(cls,timestr):
        arr = timestr.split('-')
        year = arr[0]
        month = arr[1]
        tem = arr[2].split(':')
        minite = tem[1]
        second = tem[2]
        tem2 = tem[0].split(' ')
        day = tem2[0]
        hour = tem2[1]
        list = {'year': year, 'month': month, 'day': day, 'hour': hour, 'minite': minite, 'second': second}
        return list['month'] + list['day'] + list['year'] + list['hour'] + list['minite'] + list['second']

    @classmethod
    def isDelayEnd(cls,startime,check_second):
        end_time = time.time()
        # 运行时间run_time。round()函数取整
        run_time = round(end_time - startime)
        print(run_time)
        # 计算时分秒
        #hour = run_time // 3600
        #minute = (run_time - 3600 * hour) // 60
        #second = run_time - 3600 * hour - 60 * minute

        if run_time >= check_second:
            return True
        else:
            return False
        # 输出
        #print(f'该程序运行时间：{hour}小时{minute}分钟{second}秒')